package com.lh.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器的配置类
 *
 * @Author LuoHang
 * @Date 2022-05-10 19:53
 **/
@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {
    /**
     * 添加拦截器 注入到容器中
     * @param registry 注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //创建拦截器对象
        HandlerInterceptor interceptor = new LoginInterceptor();
        //指定拦截的地址
        String[] path = {"/**"};
        //指定不拦截的地址:对登录、首页、静态资源等进行放行
        String[] excludePath = {"/user/login","/","/**/*.js","/**/*.jpg","/**/*.css"};
        registry.addInterceptor(interceptor)
                .addPathPatterns(path)
                .excludePathPatterns(excludePath);
    }
}
